package cn.com.se.jdk8;

import java.util.*;

public class LamudaTest {

    public void sort() {

        List<TestBean> test = new ArrayList<TestBean>();
        test.add(new TestBean("Sarah", 12));
        test.add(new TestBean("Barah", 10));
        test.add(new TestBean("Carah", 11));
        test.forEach(testBean -> {
            System.out.println(testBean.getName());
        });
        // 使用拉姆达表达式排序list
        test.sort((TestBean i, TestBean f) -> i.getName().compareTo(f.getName()));
        System.out.println("========================================");
        // 排序后
        test.forEach((testBean) -> {
            System.out.println(testBean.getName());
        });

    }

    /**
     * 循环map
     */
    public void forMap() {
        Map map = new HashMap();
        map.put("1", "2");
        map.put("2", "2");
        map.forEach((k, v) -> {
            System.out.println(k + "==" + v);
        });
    }

    public static void main(String[] args) {
        new LamudaTest().sort();
        new LamudaTest().forMap();
    }
}
